package edu.suda.xsap.service.impl;
import edu.suda.xsap.dto.EmployeeDto;
import edu.suda.xsap.dto.convert.EmployeeConvert;
import edu.suda.xsap.entity.Employee;
import edu.suda.xsap.mapper.EmployeeMapper;
import edu.suda.xsap.service.EmployeeService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

@Service

public class EmployeeServiceImpl implements EmployeeService {
    @Autowired
    private EmployeeMapper employeeMapper;
    @Autowired
    private EmployeeConvert employeeConvert;

    @Override
    public void delete(Integer id) {
        employeeMapper.delete(id);
    }

    @Override
    public List<EmployeeDto> findAll() {
        return employeeConvert.toDtoList(employeeMapper.findAll());
    }

    @Override
    public EmployeeDto findById(Integer id) {
        return employeeConvert.toDto(employeeMapper.findById(id));
    }

    @Override
    public EmployeeDto findByName(String name) {
        return employeeConvert.toDto(employeeMapper.findByName(name));
    }

    @Override
    public void save(Employee employee) {
        employeeMapper.save(employee);
    }

    @Override
    public void update(Employee employee) {
        employeeMapper.update(employee);
    }
}
